package com.itheima.health.dao;

import com.github.pagehelper.Page;
import com.itheima.health.pojo.User;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository // 加和不加没有影响
public interface UserDao {

    User findUserByUsername(String username);

    Page<User> findPage(String queryString);

    void add(User user);

    void setUserAndRole(@Param("userId") Integer userId, @Param("roleId")Integer roleId);

    User findById(Integer id);

    List<Integer> findRoleIdsByUserId(Integer id);

    void editUser(User user);

    void deleteUserAndRole(Integer id);

    void deleteUser(Integer id);

    List<User> findAll();

    /**
     * 修改密码身份认证
     * @param map
     * @return
     */
    @Select("select * from t_user where username = #{account} and telephone = #{telephone}")
    User findUserByTelephoneAndAccount(Map map);

    /**
     * 重置密码
     * @param map
     */
    @Update("update t_user set password = #{newPassword} where username = #{account}")
    void resetPasswordByUsername(Map map);
}
